<?php
/**
 * Created by PhpStorm.
 * User: Thanh Lâm
 * Date: 4/29/14
 * Time: 1:12 PM
 */
namespace Phalconvn\Views;
class Seo {
    public function title($value){
        $value = trim($value);
        $value =strtolower($value);
        $value = str_replace(' ', '-', $value);
        $charaterA = '#(ả|ã|á|ạ|ă|ằ|ẳ|ẵ|à|ắ|ặ|â|ầ|ẩ|ẫ|ấ|ậ)#imsU';
        $replaceCharaterA = 'a';
        $value = preg_replace($charaterA,$replaceCharaterA,$value);

        $charaterD = '#(đ|Đ)#imsU';
        $replaceCharaterD = 'd';
        $value = preg_replace($charaterD,$replaceCharaterD,$value);

        $charaterD = '#(è|ẻ|ẽ|é|ẹ|ê|ề|ể|ễ|ế|ệ)#imsU';
        $replaceCharaterD = 'e';
        $value = preg_replace($charaterD,$replaceCharaterD,$value);

        $charaterI = '#(ì|ỉ|ĩ|í|ị)#imsU';
        $replaceCharaterI = 'i';
        $value = preg_replace($charaterI,$replaceCharaterI,$value);

        $charaterO = '#(ò|ỏ|õ|ó|ọ|ô|ồ|ổ|ỗ|ố|ộ|ơ|ờ|ở|ỡ|ớ|ợ)#imsU';
        $replaceCharaterO = 'o';
        $value = preg_replace($charaterO,$replaceCharaterO,$value);

        $charaterU = '#(ù|ủ|ũ|ú|ụ|ư|ừ|ử|ữ|ứ|ự)#imsU';
        $replaceCharaterU = 'u';
        $value = preg_replace($charaterU,$replaceCharaterU,$value);

        $charaterY = '#(ỳ|ỷ|ỹ|ý)#imsU';
        $replaceCharaterY = 'y';
        $value = preg_replace($charaterY,$replaceCharaterY,$value);

        $charaterDon = '#(\'|\")#imsU';
        $replaceCharaterDon = '';
        $value = preg_replace($charaterDon,$replaceCharaterDon,$value);
        $value = preg_replace('/[^a-z0-9\-_]/','',$value);
        //loai bỏ khoang trang
        return $value;
    }
    // băm password
    public function hash($tring){
        return sha1(sha1(md5($tring).'djkasldhaLI').'DFALSDHASDJASGJD81Y2E');
    }
    public function checkHash($strPass,$password){
        if(sha1(sha1(md5($strPass).'djkasldhaLI').'DFALSDHASDJASGJD81Y2E')===$password){
            return true;
        }
        return false;
    }
    //cac function xu ly Gift Certificates
    public function hashGift($tring){
        return sha1(sha1(md5($tring).'asjkdfshlf294e*&^&&*').'DFALSDHASDJASGJD81Y2Easjkdfshlf294e*&^&&*');
    }
    public function checkHashGift($strPass,$password){
        if(sha1(sha1(md5($strPass).'asjkdfshlf294e*&^&&*').'DFALSDHASDJASGJD81Y2Easjkdfshlf294e*&^&&*')===$password){
            return true;
        }
        return false;
    }
    public function cmsReplaceString($string,$options = null){
        if($options == null){
            $str = str_replace('\"','"',$string);
            $str = str_replace("\'","'",$str);
        }else{
            $str = str_replace("'","\'",$string);
            $str = str_replace('"','\"',$str);
        }

        return $str;
    }
}